package com.zyt.controller;

import com.zyt.entity.User;
import com.zyt.service.CategoryService;
import com.zyt.service.*;
import com.zyt.util.MailUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;

@Controller
public class UserController {
    @Autowired
    private UserService userService;
    @RequestMapping("/login")
    public String login(String email, String password, HttpSession session){

        User user = userService.login(email, password);
        session.setAttribute("user",user);
        System.out.println(user.getId());
        if (user!=null){
            return "/selectByRecommend.do";
        }
        return "/login_form.jsp";
    }
    @RequestMapping("/insertRegister")
    public String insertRegister(User user, HttpSession session){
//        注册添加新用户信息，但是激活状态未激活。
        userService.insertRegister(user);
//        发送邮件验证。激活注册的帐号
        MailUtil.sendSimpleMail("1943979143@qq.com","邮箱验证","<a href=\"http://localhost:8080/dang/updateState.do?id=+"+user.getId()+"+\" >点击验证</a>");
        return "/user/verify_form.jsp";
    }
    @RequestMapping("/updateState")
    public String updateState(Integer id, HttpSession session){
//        注册添加新用户信息，但是激活状态未激活。
        userService.updateState(id);
//        发送邮件验证。激活注册的帐号
        return "/user/register_ok.jsp";
    }

}
